# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=python-lsp-server
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=1.7.4
pkgrel=1
pkgdesc='Python Language Server for the Language Server Protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
license=('spdx:MIT')
url='https://github.com/python-lsp/python-lsp-server'
depends=(
    "${MINGW_PACKAGE_PREFIX}-python"
    "${MINGW_PACKAGE_PREFIX}-python-jedi"
    "${MINGW_PACKAGE_PREFIX}-python-lsp-jsonrpc"
    "${MINGW_PACKAGE_PREFIX}-python-pluggy"
    "${MINGW_PACKAGE_PREFIX}-python-docstring-to-markdown"
    "${MINGW_PACKAGE_PREFIX}-python-ujson"
    "${MINGW_PACKAGE_PREFIX}-python-setuptools"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-python-build"
             "${MINGW_PACKAGE_PREFIX}-python-installer"
             "${MINGW_PACKAGE_PREFIX}-python-setuptools-scm"
             "${MINGW_PACKAGE_PREFIX}-python-wheel")
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        0001-python-lsp-server-1.5.0-allow-newlest-depends.patch)
sha256sums=('c84254485a4d9431b24ecefd59741d21c00165611bcf6037bd7d54d0ed06a197'
            '46612494022cb2e11b9050ae839e12de53d252d67bfa68710dffadd83b0d10e6')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-python-lsp-server-1.5.0-allow-newlest-depends.patch

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
